package com.ganbo.redpacket.controller;

import com.ganbo.redpacket.model.requset.HandOutReq;
import com.ganbo.redpacket.model.requset.RobReq;
import com.ganbo.redpacket.service.RedPacketService;
import com.ganbo.redpacket.utils.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 抢发红包控制器
 * Created by gan on 2020/1/12 14:57.
 */

@RestController
@RequestMapping("/redpacket")
public class RedPacketController {

    @Autowired
    RedPacketService redPacketService;


    /**
     * 发红包
     *
     * @param req
     * @return
     */
    @PostMapping("/handOut")
    public ResponseData handOut(@Validated @RequestBody HandOutReq req) {
        return ResponseData.success(redPacketService.handOut(req));
    }


    /**
     * 抢红包
     *
     * @param req
     * @return
     */
    @PostMapping("/rob")
    public ResponseData rob(@Validated RobReq req) {
        System.out.println("===Thread:" + Thread.currentThread().getId() + "   count:" + (++count));
        return ResponseData.success(redPacketService.rob(req));
    }

    private Integer count = 0;

}
